﻿<?php


function cmt_concise_content($content) {


                $content = preg_replace('/<br>/',"&nbsp;", $content); #PEAK ADD|To deal with sina blog
                $content = preg_replace('/<img([^>]*)>/i'," ", $content); #PEAK ADD|To deal with sina blog
                $content = preg_replace('/<a([^>]*)>/i'," ", $content); #PEAK ADD|To deal with sina blog
                $content = preg_replace('/<span([^>]*)>/i',"<span> ", $content); #PEAK ADD|To deal with sina blog
                $content = preg_replace('/<p([^>]*)>/i',"<p>", $content); #PEAK ADD|To deal with sina blog
                $content = preg_replace('/<font([^>]*)>/i',"", $content); #PEAK ADD|To deal with sina blog
                $content = preg_replace('/<\/font([^>]*)>/i',"", $content); #PEAK ADD|To deal with sina blog
                $content = preg_replace('/<strong([^>]*)>/i',"", $content); #PEAK ADD|To deal with sina blog
                $content = preg_replace('/<\/strong([^>]*)>/i',"", $content); #PEAK ADD|To deal with sina blog
                $content = preg_replace('/table/i',"", $content); #PEAK ADD|To deal with sina blog
                $content = preg_replace('/tr/i',"", $content); #PEAK ADD|To deal with sina blog
                $content = preg_replace('/td/i',"", $content); #PEAK ADD|To deal with sina blog

                mb_internal_encoding("UTF-8");
                $content = preg_replace('/<([^>]*)$/i'," ", $content); #PEAK ADD|To deal with sina blog

                $content = mb_substr($content, 0,150);


                $num1=0;$num2=0;
                preg_match_all("/(<div)/",$content,$matched1,PREG_PATTERN_ORDER);
                preg_match_all("/(<\/div)/",$content,$matched2,PREG_PATTERN_ORDER);
                $num1=count($matched1[1]);
                $num2=count($matched2[1]);
                for($i=0;$i<$num1-$num2;$i++) $content.="</div>\n";

                $num1=0;$num2=0;
                preg_match_all("/(<font)/",$content,$matched1,PREG_PATTERN_ORDER);
                preg_match_all("/(<\/font)/",$content,$matched2,PREG_PATTERN_ORDER);
                $num1=count($matched1[1]);
                $num2=count($matched2[1]);
                for($i=0;$i<$num1-$num2;$i++) $content.="</font>\n";

                $num1=0;$num2=0;
                preg_match_all("/(<b>)/",$content,$matched1,PREG_PATTERN_ORDER);
                preg_match_all("/(<\/b)/",$content,$matched2,PREG_PATTERN_ORDER);
                $num1=count($matched1[1]);
                $num2=count($matched2[1]);
                for($i=0;$i<$num1-$num2;$i++) $content.="</b>\n";

                $num1=0;$num2=0;
                preg_match_all("/(<em>)/",$content,$matched1,PREG_PATTERN_ORDER);
                preg_match_all("/(<\/em)/",$content,$matched2,PREG_PATTERN_ORDER);
                $num1=count($matched1[1]);
                $num2=count($matched2[1]);
                for($i=0;$i<$num1-$num2;$i++) $content.="</em>\n";

                $num1=0;$num2=0;
                preg_match_all("/(<blockquote)/",$content,$matched1,PREG_PATTERN_ORDER);
                preg_match_all("/(<\/blockquote)/",$content,$matched2,PREG_PATTERN_ORDER);
                $num1=count($matched1[1]);
                $num2=count($matched2[1]);
                for($i=0;$i<$num1-$num2;$i++) $content.="</blockquote>\n";
/*	
                $content.="...\n";
		$content.="<br><div align=right><a href=".get_permalink();
		$content .= "> ". __("Go>>") ."</a>";
		$content .= " &nbsp; </div>";
*/

		return $content;
}

define('WP_USE_THEMES', true);
$blog='NULL';
$blogdata='NULL';
$optiondomain = 'system';
$_REQUEST['b']='system';

require('private.php');
require(CONFIGPATH . 'wp-config.php');
require_once( ABSPATH . WPINC . '/registration-functions.php');

$time_begin=date("u");

require('my_portal.lib');

get_currentuserinfo();

$SITE_TITLE = get_settings('site_title');



?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head profile="http://gmpg.org/xfn/11">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title><?php echo $SITE_TITLE ?>(Beta)</title>

<link rel="stylesheet" href="./comment_style.css" type="text/css" media="screen" />

<style type="text/css" media="screen">
</style>
</head>
<body>

<?php if ($user_identity) { ?>
<div id="status">
	<div class="description"><?php  echo "logged in as <em>$user_identity</em>"?> [<a href="login?action=logout">Log Out</a>]</div>
Lyceum
</div>
<?php } else { ?>
<div id="status" class="closed">&nbsp;</div>
<?php }
	
$page_num=$_POST["page_num"];

$cmd_page_init=$_POST["cmd_page_init"];

$cmd_page_next=$_POST["cmd_page_next"];

$cmd_page_pre=$_POST["cmd_page_pre"];

$page_offset=$_POST["page_offset"];

$cmd_page_offset=$_POST["cmd_page_offset"];

$cmt_auth=stripslashes($_POST["cmt_auth"]);
$blog_auth=$_POST["blog_auth"];

$search_started=$_POST["search_started"];


if($cmd_page_next) $page_num = $page_num+1;
if($cmd_page_pre) $page_num = $page_num-1;
if($cmd_page_offset) $page_num = $page_offset;
if($cmd_page_init) $page_num = 1;

if(!$cmt_auth )  $search_started=0;

if( ( $cmt_auth ) && !$search_started ) { $page_num=1; $search_started=1;}


if($page_num<=1)	$page_num=1;


 	
 ?>

<form action="comment_list.php" method="post">
<input type="hidden" name="page_num" value="<?php echo $page_num; ?>" size=10> 
<input type="hidden" name="search_started" value="<?php echo $search_started; ?>" size=10>

&nbsp;
<font size=2>
<a href="./portal.php"> << <?php _e("Front Page"); ?> </a>
</font><br>
	
<div style="float:right;margin-right:20px">
&nbsp; &nbsp; 第 <?php echo $page_num; ?> 页 
<input type="submit" name="cmd_page_init" value="第一页" size="17" />
&nbsp;<input type="submit" name="cmd_page_pre" value="前一页" size="17" />
&nbsp;<input type="submit" name="cmd_page_next" value="下一页" size="17" />
&nbsp;&nbsp;
评论者： <input type="text" name="cmt_auth" value="<?php echo $cmt_auth; ?>" size=10> 
<input type="submit" name="search" value="检索">
</div>
<!-- 
博客作者： <input type="text" name="blog_auth" value="<?php echo $blog_auth; ?>" size=10>  
-->

<div id="header">
<h1> Comment List </h1>
</div>

<table border=0 align=center width=90% class="mybody">
<tr>
<td>


<ul>
                
<?php
	// global $current_user;
   mb_internal_encoding("UTF-8");//PEAK
   $comment_num=20;
   $each_post_comment_num=6;
   if($cmt_auth)    $each_post_comment_num=12;
   $str_len=36;
   $off_set = 0;
   
   if($page_num) $off_set=( $page_num - 1) * $comment_num;
   if($cmt_auth) $auth_cond = " comment_author like \"%$cmt_auth%\"  and ";
   if($blog_auth) $auth_cond = " user_id like \"%$blog_auth%\"  and ";
    $sql = "SELECT $wpdb->posts.ID as ID, post_title,post_author as user_id,post_password, comment_ID,  SUBSTRING(post_content,1,1552) as content, post_date as p_date,
    comment_post_ID, comment_author,max(comment_date_gmt) as comment_date_gmt, comment_approved,
    comment_type,comment_author_url,$wpdb->blogs.slug
    FROM $wpdb->comments
    inner JOIN $wpdb->posts ON ($wpdb->comments.comment_post_ID = $wpdb->posts.ID)
    inner JOIN $wpdb->post2cat ON ($wpdb->post2cat.post_id = $wpdb->posts.ID)
    inner JOIN $wpdb->categories ON ($wpdb->post2cat.category_id = $wpdb->categories.cat_ID)
    inner join $wpdb->blogs on $wpdb->categories.blog = $wpdb->blogs.id
    WHERE 
    comment_type = '' AND
    $auth_cond
	comment_approved = '1' AND
    post_password = ''
    and `$wpdb->blogs`.status=\"active\" and `$wpdb->posts`.post_status=\"publish\"
    group by ID
    ORDER BY comment_date_gmt DESC";
    $sql.=" LIMIT $off_set, $comment_num ";

    $comments = $wpdb->get_results($sql);
    foreach ($comments as $comment){

 	$profileuser = new WP_User($comment->user_id);
	$comment->content = cmt_concise_content($comment->content);

	$out_put = NULL;
	$out_put .= "\n<li>";
	$out_put .= "<h3> ";

	$out_put .= " <a href=\"".$comment->slug."/?p=$comment->ID". "\" >" . $comment->post_title ."</a>";
    	$out_put .= "<font size=2> <b>".$profileuser->display_name."</b> [$comment->p_date] </font></h3>";

	$out_put .="<blockquote class='post-quote'> ";	
	$out_put .= $comment->content;	
	$out_put .="... </blockquote> &nbsp;[". __("Comments").__("List")."]";	
	$out_put .="\n<ol>\n";	

    	$sql = "SELECT DISTINCT comment_ID, comment_post_ID, comment_author,
    comment_date_gmt + interval 8 hour as comment_date, comment_approved, comment_type,comment_author_url,
    SUBSTRING(comment_content,1,100) AS com_excerpt
    FROM $wpdb->comments 
    where
    $wpdb->comments.comment_post_ID = $comment->ID  AND
    comment_approved = '1' 
    order by comment_date desc
    limit 0, $each_post_comment_num
    ";
//    $auth_cond
    	$comment_lists = $wpdb->get_results($sql);
	$index=0;
    	foreach ($comment_lists as $cmt){
		$cmt->com_excerpt = mb_substr($cmt->com_excerpt, 0,40);
		$out_put .= "<li> ";
		$out_put .= "$cmt->com_excerpt .. ";
		$out_put .= " <a href=\"".$comment->slug."/?p=$comment->ID". "#comment-" . $cmt->comment_ID . "\" >" . strip_tags($cmt->comment_author)."</a>";
		$out_put .= " <font size=1>". $cmt->comment_date. "</font> </li>";
	}
	$out_put .= "<li stype=\"list-style-type:none;\"><a href=\"{$comment->slug}/?p={$comment->ID}#respond\">". __("More...")."</a> &nbsp;&nbsp; ";
	$out_put .= "<a href=\"{$comment->slug}/?p={$comment->ID}#respond\">". __("Add comment")."</a>";
	$out_put .="</ol>\n";	
	
		

	echo $out_put;


    }
 
?>
</ul>
</td>
</tr>
<tr>
<td>


<!--PEAK   --->

&nbsp;
&nbsp;
&nbsp;
<?php

echo "&nbsp; &nbsp; 第 $page_num 页 ";
?>

 <input type="submit" name="cmd_page_init" value="第一页" size="17" />

  <input type="submit" name="cmd_page_pre" value="前一页" size="17" />
  <input type="submit" name="cmd_page_next" value="下一页" size="17" />
  	  
  直接跳到第  <input type="text" name="page_offset" value="<?php  echo $page_num; ?>" size="7" />页
  <input type="submit" name="cmd_page_offset" value="GO" />
<br>
<!--- PEAK END --->

</td>
</tr>
</table>

<script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-2718547-1";
urchinTracker();
</script>

</form>


</body>
</html>
